(function(){
	var AjaxCrud = QualityCheck.AjaxCRUD;
	var serverUrl = QualityCheck.GPUD.ServiceConfig;
	var currentPage = 1;
	var pageSize = 10;
	var totalSize;
	var now = 0;
	var dataCache = [];
	$(function(){
		var usercode = $("#user-name",parent.parent.document).attr("code");
		var userkey = $("#user-name",parent.parent.document).attr("key");
		var usertype = $("#user-name",parent.parent.document).attr("usertype");
		keyCheck(usercode,usertype,userkey,function(){
			initSmPages();
			window.onresize = function () {
				initSmPages();
			};
			pagebtns();
			initUser(currentPage,pageSize);
			getAllRoll();
		});
	});
	function initUser(currentpage,pagesize){
		var userKey = $("#user-name",parent.parent.document).attr("key");	
		var schoolcode = $("#user-name",parent.parent.document).attr("schoolcode");
		var islock = $("#user-lock option:selected").val();
		var userType = $("#user-role option:selected").val();
		var name = encodeURI($("#user-name").val());
		var data = {
				cmd:"getAllUserWithStudent",
				model:"user",
				userKey:userKey,
				data:{
					currentpage:currentpage,
					pagesize:pagesize,
					alias:name,
					islock:islock,
					usertype:userType,
					schoolcode:schoolcode,
				},
				remark:"",
		};
		AjaxCrud.get(serverUrl.ServerLoginUrl,data,function(res){
			var content = "";
			var pagecontent = "<div class=\"pages-btn-next\">&gt;&gt;</div>";
			if(res.result == 1 && res.data != undefined && res.data != ""){
				var data = res.data.data;
				var total = res.data.total;
				totalSize = Math.ceil(total/pagesize);
				if(totalSize <= 5 && totalSize >0){
					for(var i = totalSize-1 ; i >= 0; i--){
						if(i == currentpage-1){
							pagecontent += "<div class=\"pages-btn page-btn-select\">"+(i + 1)+"</div>"; 
						}else{
							pagecontent += "<div class=\"pages-btn\">"+(i + 1)+"</div>"; 
						}
					}
				}else if(totalSize == 0){
					pagecontent += "<div class=\"pages-btn\">1</div>";
				}else if(totalSize > 5){
					var lastp = (now*5)+5;
					if(lastp > totalSize){
						lastp = totalSize;
					}
					for(var i = lastp-1 ; i >= (now*5); i--){
						if(i == currentpage-1){
							pagecontent += "<div class=\"pages-btn page-btn-select\">"+(i + 1)+"</div>"; 
						}else{
							pagecontent += "<div class=\"pages-btn\">"+(i + 1)+"</div>"; 
						}
					}
				}
				pagecontent += "<div class=\"pages-btn-last\">&lt;&lt;</div>";
				$("#user-page").empty();
				$("#user-page").append(pagecontent);
				
				$(".pages-btn").unbind("click");
				$(".pages-btn").click(function(){
					dataCache = [];
					$(".pages-btn").removeClass("page-btn-select");
					$(this).addClass("page-btn-select");
					currentPage = parseInt($(this).text());
					initUser(currentPage,pageSize);
				});
				
				$(".pages-btn-last").unbind("click");
				$(".pages-btn-last").click(function(){
					if(totalSize <= 5 && totalSize >0){
						return false;
					}else if(totalSize == 0){
						return false;
					}else if(totalSize > 5){
						if(now > 0){
							now --;
							initUser((now*5+1),pageSize);
						}else{
							return false;
						}
					}
				});
				
				$(".pages-btn-next").unbind("click");
				$(".pages-btn-next").click(function(){
					if(totalSize <= 5 && totalSize >0){
						return false;
					}else if(totalSize == 0){
						return false;
					}else if(totalSize > 5){
						if(totalSize%5 == 0){
							if((now+1) < totalSize/5){
								now ++;
								initUser((now*5+1),pageSize);
							}else{
								return false;
							}
						}else{
							if((now+1) <= (totalSize-totalSize%5)/5){
								now ++;
								initUser((now*5+1),pageSize);
							}else{
								return false;
							}
						}
					}
				});
				if(data.length > 0){
					for(var i = 0; i < data.length; i++){
						for(var key in data[i]){
							if(data[i][key] == null || data[i][key] == "null" ){
								data[i][key] = "";
							}
						}
						var lockBtns = "";
						if(data[i].islock == true || data[i].islock == "true"){
							lockBtns = "<div class=\"table-edit\" dataindex = \""+i+"\" usercode=\""+data[i].usercode+"\" userkey=\""+data[i].userkey+"\" usertype=\""+data[i].usertype+"\" title=\"编辑\"></div>" +
							"<div class=\"table-locked\" usercode = '"+data[i].usercode+"' title=\"锁定\"></div>";
						}else if(data[i].islock == false || data[i].islock == "false"){
							lockBtns = "<div class=\"table-unlocked\" usercode = '"+data[i].usercode+"' title=\"解锁\"></div>" +
							"<div class=\"table-delete\" dataindex = \""+i+"\" usercode=\""+data[i].usercode+"\" title=\"删除\"></div>";
						}
						var roleCont = "";
						if(data[i].usertype == "0"){
							roleCont = "<div class=\"table-code\" title='"+data[i].name+"'>"+substr(isUndefined(data[i].name),13)+"</div>";
						}else{
							roleCont = "<div class=\"table-code\">"+isUndefined(data[i].email)+"</div>";
						} 
						content += "<div class=\"table-trs\">" +
							"<div class=\"tables-headimg\">" +
								"<img src=\"../../../../../../"+ServiceName+data[i].headimg+"\" width=\"100%\" height=\"100%\"/>" +
							"</div>" +
							"<div class=\"tables-left\">" +
								"<div class=\"table-name\" style=\"width:200px;text-align:left\" title=\""+data[i].alias+"\"\>"+substr(data[i].alias,13)+"</div>" +
								"<div class=\"table-code\">"+data[i].usercode+"</div>" +
							"</div>" +
							"<div class=\"tables-middle\">" +
								"<div class=\"table-class\" title=\"手机号\">"+isUndefined(data[i].cellphone)+"</div>" +
								roleCont +
							"</div>" +
							"<div class=\"tables-right\">" +
								"<div class=\"table-address\" title=\""+data[i].address+"\">"+substr(data[i].address,12)+"</div>" +
								"<div class=\"table-oprate\">" +
									"<div class=\"table-detail\" dataindex = \""+i+"\" usercode=\""+data[i].usercode+"\" usertype=\""+data[i].usertype+"\" title=\"详情\"></div>" +
									lockBtns +
								"</div>" +
							"</div>" +
						"</div>";
						dataCache.push(data[i]);
					}
					$("#user-data-show").empty();
					$("#user-data-show").append(content);
					
					$(".table-trs").unbind("hover");
					$(".table-trs").hover(function(){
						$(this).find(".table-oprate").show();
					},function(){
						$(".table-oprate").hide();
					});
					
					$(".table-detail").unbind("click");
					$(".table-detail").click(function(){
						$("#right-user-tables").hide();
						$("#detailform").hide();
						$("#user-detailform").hide();
						var index = parseInt($(this).attr("dataindex"));
						var usertype = $(this).attr("usertype");
						if(usertype == "0"){//管理员
							$("#user-detailform").show();
							$("#user-detailform").contents().find("input").attr("readonly","readonly");
							$("#user-detailform").contents().find("input").css("background-color","#E5E5E5");
							$("#user-detailform").contents().find("select").attr("disabled","disabled");
							$("#user-detailform").contents().find("select").css("background-color","#E5E5E5");
							$("#user-detailform").contents().find("#save-btns-content").hide();
							$("#user-detailform").contents().find(".user-islock").show();
							//$("#user-detailform").contents().find("#user-pwd").hide();
							$("#user-detailform").contents().find("#back-to-table").unbind("click");
							$("#user-detailform").contents().find("#back-to-table").click(function(){
								$("#user-detailform").hide();
								$("#right-user-tables").show();
								dataCache = [];
								currentPage = 1;
								initUser(currentPage,pageSize);
							});
							showUserData(dataCache[index]);
							$("#user-detailform").contents().find("#choice-student").unbind("click");
							$("#user-detailform").contents().find("#user-student").attr("disabled","disabled");

						}else{
							$("#detailform").show();
							$("#detailform").contents().find("input").attr("readonly","readonly");
							$("#detailform").contents().find("input").css("background-color","#E5E5E5");
							$("#detailform").contents().find("select").attr("disabled","disabled");
							$("#detailform").contents().find("select").css("background-color","#E5E5E5");
							$("#detailform").contents().find("#save-btns-content").hide();
							$("#detailform").contents().find(".user-islock").show();
							//$("#detailform").contents().find("#user-pwd").hide();
							$("#detailform").contents().find("#back-to-table").unbind("click");
							$("#detailform").contents().find("#back-to-table").click(function(){
								$("#detailform").hide();
								$("#right-user-tables").show();
								dataCache = [];
								currentPage = 1;
								initUser(currentPage,pageSize);
							});
							showData(dataCache[index]);
							$("#detailform").contents().find("#choice-student").unbind("click");
							$("#detailform").contents().find("#user-student").attr("disabled","disabled");
						}
					});
					
					$(".table-edit").unbind("click");
					$(".table-edit").click(function(){
						$("#right-user-tables").hide();
						$("#detailform").hide();
						$("#user-detailform").hide();
						var index = parseInt($(this).attr("dataindex"));
						var userkey = $(this).attr("userkey");
						var usertype = $(this).attr("usertype");
						if(usertype == "0"){//管理员
							$("#user-detailform").show();
							$("#user-detailform").contents().find("input").removeAttr("readonly","readonly");
							$("#user-detailform").contents().find("input").css("background-color","#FFF");
							$("#user-detailform").contents().find("select").removeAttr("disabled","disabled");
							$("#user-detailform").contents().find("select").css("background-color","#FFF");
							$("#user-detailform").contents().find("#user-usertype").attr("disabled","disabled");
							$("#user-detailform").contents().find("#user-usertype").css("background-color","#E5E5E5");
							$("#user-detailform").contents().find("#user-student").css("background-color","#E5E5E5");
							$("#user-detailform").contents().find("#user-usercode").attr("disabled","disabled");
							$("#user-detailform").contents().find("#user-usercode").css("background-color","#E5E5E5");
							$("#user-detailform").contents().find("#save-btns-content").show();
							$("#user-detailform").contents().find(".user-islock").hide();
							//$("#user-detailform").contents().find("#user-pwd").show();
							$("#user-detailform").contents().find("#back-to-table").unbind("click");
							$("#user-detailform").contents().find("#back-to-table").click(function(){
								$("#user-detailform").hide();
								$("#right-user-tables").show();
								dataCache = [];
								currentPage = 1;
								initUser(currentPage,pageSize);
							});
							showUserData(dataCache[index]);
							$("#user-detailform").contents().find("#user-add").unbind("click");
							$("#user-detailform").contents().find("#user-add").click(function(){
								if(checkUser1() && check2("check-fail","user-detailform")){
									updateUser(userkey,"user-detailform");
								}
							});
						}else{
							$("#detailform").show();
							$("#detailform").contents().find("input").removeAttr("readonly","readonly");
							$("#detailform").contents().find("input").css("background-color","#FFF");
							$("#detailform").contents().find("select").removeAttr("disabled","disabled");
							$("#detailform").contents().find("select").css("background-color","#FFF");
							$("#detailform").contents().find("#user-usertype").attr("disabled","disabled");
							$("#detailform").contents().find("#user-usertype").css("background-color","#E5E5E5");
							$("#detailform").contents().find("#user-usercode").attr("readonly","readonly");
							$("#detailform").contents().find("#user-usercode").css("background-color","#E5E5E5");
							$("#detailform").contents().find("#user-student").css("background-color","#E5E5E5");
							$("#detailform").contents().find("#save-btns-content").show();
							$("#detailform").contents().find(".user-islock").hide();
							//$("#detailform").contents().find("#user-pwd").show();
							$("#detailform").contents().find("#back-to-table").unbind("click");
							$("#detailform").contents().find("#back-to-table").click(function(){
								$("#detailform").hide();
								$("#right-user-tables").show();
								dataCache = [];
								currentPage = 1;
								initUser(currentPage,pageSize);
							});
							showData(dataCache[index]);
							$("#detailform").contents().find("#user-add").unbind("click");
							$("#detailform").contents().find("#user-add").click(function(){
								if(checkUser() && check2("check-fail","detailform")){
									updateUser(userkey,"detailform");
								}
							});
							$("#detailform").contents().find("#choice-student").unbind("click");
							$("#detailform").contents().find("#choice-student").click(function(){
								var studentcodes = $("#detailform").contents().find("#user-student").attr("studentcodes").split(",");
								studentChoice(function(){
									$("#student-choice-name",parent.parent.document).show();
									$("#student-choice-submit",parent.parent.document).show();
									$(".selectL-title",parent.parent.document).text("待选学生");
									$(".selectR-title ",parent.parent.document).text("已选学生");
									$(".student-choice-title-name",parent.parent.document).text("选择学生");
									studentSeachMenu();
									initStudents(1,100000,studentcodes);
									selectLR();
									$("#sub",parent.parent.document).unbind("click");
									$("#sub",parent.parent.document).click(function(){
										var selVal = [];
										var studentCode = [];
										var imei = [];
										var rightSel = $("#selectR",parent.parent.document);
										rightSel.find("option",parent.parent.document).each(function(){
											selVal.push(this.value);
											studentCode.push($(this).attr("studentcode"));
											imei.push($(this).attr("imei"));
										});
										selVals = selVal.join(",");
										studentCodes = studentCode.join(",");
										for(var key in imei){
											if(imei[key] == undefined || imei[key] == "undefined" || imei[key] == null || imei[key] == "null"){
												imei[key] = "null";
											}
										}
										imeis = imei.join(",");
										$(".index-dialog-cover",parent.parent.document).hide();
										$("#student-choice-dialog",parent.parent.document).hide();
										$("#detailform").contents().find("#user-student").empty();
										$("#detailform").contents().find("#user-student").val(selVals);
										$("#detailform").contents().find("#user-student").attr("studentcodes",studentCodes);
										$("#detailform").contents().find("#user-student").attr("imeis",imeis);
										$("#detailform").contents().find("#user-student").focus();
										$("#selectR",parent.parent.document).empty();
									});
									$("#student-choice-submit",parent.parent.document).unbind("click");
									$("#student-choice-submit",parent.parent.document).click(function(){
										initStudents(1,100000,studentcodes);
									});
									$("#student-choice-name",parent.parent.document).unbind("keyup");
									$("#student-choice-name",parent.parent.document).keyup(function(){
										this.value=this.value.replace(/^ +| +$/g,'');
									});
									document.onkeydown = function(e){ 
										var ev = document.all ? window.event : e;
										if(ev.keyCode==13) {
											initStudents(1,100000,studentcodes);
										}
									};
								});
							});
						}
						check1("user-cellphone",checkMobilePhone,"checkAddNull","detailform");
						check1("user-email",checkEmail,"check","detailform");
						check1("user-alias",isNull,"null","detailform");
						check1("user-student",isNull,"null","detailform");
						check1("user-usercode",isNull,"null","detailform");
						checkPwd1("user-password","user-confirm-password","detailform");
						//管理员编辑页面字段验证
						check1("user-cellphone",checkMobilePhone,"check","detailform");
						check1("user-email",checkEmail,"check","detailform");
						check1("user-alias",isNull,"null","detailform");
						check1("user-student",isNull,"null","detailform");
						check1("user-usercode",isNull,"null","detailform");
						checkPwd1("user-password","user-confirm-password","detailform");
						
					});
					$(".table-locked").unbind("click");
					$(".table-locked").click(function(){
						var usercode = $(this).attr("usercode");
						deleteBox("确定要锁定吗？",function(){
							lockUser(usercode);
						});
					});
					
					$(".table-unlocked").unbind("click");
					$(".table-unlocked").click(function(){
						var usercode = $(this).attr("usercode");
						deleteBox("确定要解锁吗？",function(){
							unlockUser(usercode);
						});
					});
					
					$(".table-delete").unbind("click");
					$(".table-delete").click(function(){
						var usercode = $(this).attr("usercode");
						deleteBox("确定要删除吗？",function(){
							deleteUser(usercode);
						});
					});
				}else{
					content += "<div class=\"table-trs\">" +
									"<div class=\"no-data-show\">没有查到相关结果！</div>" +
								"</div>";
					$("#user-data-show").empty();
					$("#user-data-show").append(content);
				}
			}else{
				content += "<div class=\"table-trs\">" +
								"<div class=\"no-data-show\">没有查到相关结果！</div>" +
							"</div>";
				$("#user-data-show").empty();
				$("#user-data-show").append(content);
			}
		},null,null);	
	}
	function showData(data){
		for(key in data){
			$("#detailform").contents().find("#user-password").val("");
			$("#detailform").contents().find("#user-confirm-password").val("");		
			if(key == "stunames"){
				$("#detailform").contents().find("#user-student").val("");
				$("#detailform").contents().find("#user-student").attr("studentcodes","");
				$("#detailform").contents().find("#user-student").attr("imeis","");	
				$("#detailform").contents().find("#user-student").val(data.stunames);
				$("#detailform").contents().find("#user-student").attr("studentcodes",data.stucodes);
				$("#detailform").contents().find("#user-student").attr("imeis",data.stuimeis);					
			}
			if($("#detailform").contents().find("#user-" + key).length != 0){
				if($("#detailform").contents().find("#user-" + key)[0].tagName.toLowerCase() == "input"){
					if(key == "lockdate"){
						$("#detailform").contents().find("#user-lockdate").val(getFormatDateByLong(parseInt(data.lockdate)*1000,"yyyy-MM-dd hh:mm"));						
					}else{
						$("#detailform").contents().find("#user-" + key).val(data[key]);
					}
				}else if($("#detailform").contents().find("#user-" + key)[0].tagName.toLowerCase() == "select"){
					var options = $("#detailform").contents().find("#user-" + key + " option");
					for(var i = 0; i < options.length; i++){
						if(options[i].value == data[key]){
							options[i].selected = true;
						}
					}
					if(key == "usertype"){
						if(data[key] == "0" || data[key] == "2"){
							$("#detailform").contents().find("#user-font-student").hide();
							$("#detailform").contents().find("#user-student-td").hide();
							$("#detailform").contents().find("#user-role-td-right").hide();
							$("#detailform").contents().find("#choice-student").hide();
							$("#detailform").contents().find("#user-student-ex").hide();
							if(data[key] == "0"){
								$("#detailform").contents().find("#user-font-role").show();
								$("#detailform").contents().find("#user-role-td").show();
								$("#detailform").contents().find("#user-role-td-right").show();
							}else{
								$("#detailform").contents().find("#user-font-role").hide();
								$("#detailform").contents().find("#user-role-td").hide();
								$("#detailform").contents().find("#user-role-td-right").hide();
							}
						}else if(data[key] == "1"){
							$("#detailform").contents().find("#user-font-student").show();
							$("#detailform").contents().find("#user-student-td").show();
							$("#detailform").contents().find("#user-role-td-right").show();
							$("#detailform").contents().find("#choice-student").show();
							$("#detailform").contents().find("#user-font-role").hide();
							$("#detailform").contents().find("#user-role-td").hide();
							$("#detailform").contents().find("#user-role-td-right").hide();
						}
					}
//					$("#detailform").contents().find("#user-cellphone").bind({
//						blur:function(){
//							if($("#detailform").contents().find("#user-cellphone").val().length != 0 ){
//								var usercode = $("#detailform").contents().find("#user-cellphone").val();
//								if(checkMobilePhone(usercode)){
//									$("#detailform").contents().find("#user-usercode").val(usercode);
//									
//								}
//							}
//						},
//						focus:function(){
//							if($("#detailform").contents().find("#user-cellphone").val().length != 0 ){
//								var usercode = $("#detailform").contents().find("#user-cellphone").val();
//								if(checkMobilePhone(usercode)){
//									$("#detailform").contents().find("#user-usercode").val("");
//									
//								}
//							}
//						}
//					});
					
					
				}
			}
		}
	}
	function showUserData(data){
		for(key in data){
			$("#user-detailform").contents().find("#user-password").val("");
			$("#user-detailform").contents().find("#user-confirm-password").val("");		
			if(key == "stunames"){
				$("#user-detailform").contents().find("#user-student").val("");
				$("#user-detailform").contents().find("#user-student").attr("studentcodes","");
				$("#user-detailform").contents().find("#user-student").attr("imeis","");	
				$("#user-detailform").contents().find("#user-student").val(data.stunames);
				$("#user-detailform").contents().find("#user-student").attr("studentcodes",data.stucodes);
				$("#user-detailform").contents().find("#user-student").attr("imeis",data.stuimeis);					
			}
			if($("#user-detailform").contents().find("#user-" + key).length != 0){
				if($("#user-detailform").contents().find("#user-" + key)[0].tagName.toLowerCase() == "input"){
					if(key == "lockdate"){
						$("#user-detailform").contents().find("#user-lockdate").val(getFormatDateByLong(parseInt(data.lockdate)*1000,"yyyy-MM-dd hh:mm"));						
					}else{
						$("#user-detailform").contents().find("#user-" + key).val(data[key]);
					}
				}else if($("#user-detailform").contents().find("#user-" + key)[0].tagName.toLowerCase() == "select"){
					var options = $("#user-detailform").contents().find("#user-" + key + " option");
					for(var i = 0; i < options.length; i++){
						if(options[i].value == data[key]){
							options[i].selected = true;
						}
					}
					if(key == "usertype"){
						if(data[key] == "0" || data[key] == "2"){
							$("#user-detailform").contents().find("#user-font-student").hide();
							$("#user-detailform").contents().find("#user-student-td").hide();
							$("#user-detailform").contents().find("#user-role-td-right").hide();
							$("#user-detailform").contents().find("#choice-student").hide();
							$("#user-detailform").contents().find("#user-student-ex").hide();
							if(data[key] == "0"){
								$("#user-detailform").contents().find("#user-font-role").show();
								$("#user-detailform").contents().find("#user-role-td").show();
								$("#user-detailform").contents().find("#user-role-td-right").show();
							}else{
								$("#user-detailform").contents().find("#user-font-role").hide();
								$("#user-detailform").contents().find("#user-role-td").hide();
								$("#user-detailform").contents().find("#user-role-td-right").hide();
							}
						}else if(data[key] == "1"){
							$("#user-detailform").contents().find("#user-font-student").show();
							$("#user-detailform").contents().find("#user-student-td").show();
							$("#user-detailform").contents().find("#user-role-td-right").show();
							$("#user-detailform").contents().find("#choice-student").show();
							$("#user-detailform").contents().find("#user-font-role").hide();
							$("#user-detailform").contents().find("#user-role-td").hide();
							$("#user-detailform").contents().find("#user-role-td-right").hide();
						}
					}					
				}
			}
		}
	}
	function lockUser(usercodes){
		var userKey = $("#user-name",parent.parent.document).attr("key");
		var lockdate =strToDate(getFormatDate(new Date()))/1000;
		var data = {
				cmd:"lockUserByUsercodes",
				model:"user",
				userKey:userKey,
				data:{
					usercodes:[usercodes],
					lockdate:lockdate,
				},
				remark:"",						
		};
		processBegin("正在锁定中···");
		AjaxCrud.get(serverUrl.ServerLoginUrl,data,function(res){
			if(res.result == 1 && res.data != undefined && res.data != ""){
				processEnd("锁定成功");
				initUser(currentPage,pageSize);
			}else{
				processError("锁定失败");
			}
		},null,null);
	}
	
	//解锁  
	function unlockUser(usercode){
		var userKey = $("#user-name",parent.parent.document).attr("key");
		var param = {};
		param["usercode"] = usercode;
		param["lockdate"] = strToDate(getFormatDate(new Date()))/1000;
		
		var data = {
				cmd:"unlockUserByUsercodes",
				model:"user",
				userKey:userKey,
				data:param,
				remark:"",						
		};
		processBegin("正在解锁中···");
		AjaxCrud.get(serverUrl.ServerLoginUrl,data,function(res){
			if(res.result == 1 && res.data != undefined && res.data != ""){
				processEnd("解锁成功");
				initUser(currentPage,pageSize);				
			}else{
				processError("解锁失败");
			}
		},null,null);
		
	}
	
	//删除
	function deleteUser(usercode){
		var userKey = $("#user-name",parent.parent.document).attr("key");
		var param = {};
		param["usercode"] = usercode;
		
		var data = {
				cmd:"delete",
				model:"user",
				userKey:userKey,
				data:param,
				remark:"",						
		};
		processBegin("正在删除中···");
		AjaxCrud.get(serverUrl.ServerLoginUrl,data,function(res){
			if(res.result == 1 && res.data != undefined && res.data != ""){
				processEnd("删除成功");
				initUser(currentPage,pageSize);				
			}else{
				processError("删除失败");
			}
		},null,null);
		
	}
	
	function updateUser(userkey,name){
		var userKey = $("#user-name",parent.parent.document).attr("key");
		var schoolcode = $("#user-name",parent.parent.document).attr("schoolcode");
		var params = {};
		var param = {};
		params["alias"] = encodeURI($("#" + name).contents().find("#user-alias").val());
		params["usertype"] = encodeURI($("#" + name).contents().find("#user-usertype option:selected").val());		
		params["region"] = encodeURI($("#" + name).contents().find("#user-region").val());
		params["address"] = encodeURI($("#" + name).contents().find("#user-address").val());
		params["cellphone"] = $("#" + name).contents().find("#user-cellphone").val();
		params["email"] = encodeURI($("#" + name).contents().find("#user-email").val());
		params["remark"] = encodeURI($("#" + name).contents().find("#user-remark").val());			
		params["usercode"] = encodeURI($("#" + name).contents().find("#user-usercode").val());
		//params["password"] = encodeURI($("#" + name).contents().find("#user-password").val());
		if($("#" + name).contents().find("#user-usertype option:selected").val() == "1"){
			params["studentcode"] = encodeURI($("#" + name).contents().find("#user-student").attr("studentcodes"));
			params["stuimeis"] = $("#" + name).contents().find("#user-student").attr("imeis");
		}else if($("#" + name).contents().find("#user-usertype option:selected").val() == "0"){
			params["code"] = encodeURI($("#" + name).contents().find("#user-code option:selected").val());
			//params["userkey"] = userkey;
		}
		params["schoolcode"] = schoolcode;
		for(var key in params){
			if(params[key] != ""){
				param[key] = params[key];
			}
		}
		var data = {
				cmd:"updateUserInfo",
				model:"user",
				userKey:userKey,
				data:param,
				remark:"",						
		};
		processBegin("正在运行中···");
		AjaxCrud.get(serverUrl.ServerLoginUrl,data,function(res){
			if(res.result == 1 && res.data != undefined && res.data != ""){
				processEnd("修改用户成功");
				
			}else{
				processError("修改用户失败");
			}
		},null,null);			
	}
	function getAllRoll(){
		var userKey = $("#user-name",parent.parent.document).attr("key");	
		var schoolcode = $("#user-name",parent.parent.document).attr("schoolcode");
		var data = {
				cmd:"getRole",
				model:"license",
				userKey:userKey,
				data:{
					schoolcode:schoolcode,
				},
				remark:"",
		};
		AjaxCrud.get(serverUrl.ServerLoginUrl,data,function(res){
			var content = "<option value=''>- - -</option>";
			if(res.result == 1 && res.data != undefined && res.data != ""){
				var data = res.data.data;
				if(data.length > 0){
					for(var i = 0; i < data.length; i++){
						content += "<option value = '"+data[i].code+"'>"+data[i].name+"</option>";
					}
				}else{
					content += "<option>- - -</option>";
				}
			}else{
				content += "<option>- - -</option>";
			}
			$("#user-detailform").contents().find("#user-code").html(content);
		});
	}
	function substr(str,len){
		if(str != undefined){
			if(str.length > len){
				str = str.substring(0,len-2)+"...";
				return str;
			}else{
				return str;
			}
		}else{
			return "";
		}
	}
	function isUndefined(param){
		if(param == undefined){
			param = "";
		}
		return param;
	}
	function pagebtns(){
		$("#user-name").unbind("keyup");
		$("#user-name").keyup(function(){
			this.value=this.value.replace(/^ +| +$/g,'');
		});
		document.onkeydown = function(e){ 
			$("select").blur();
		    var ev = document.all ? window.event : e;
		    if(ev.keyCode==13) {
		    	initUser(1,pageSize);
		    }
		};
		$("#user-search-btn").click(function(){
			dataCache = [];
			initUser(1,pageSize);
		});
		
	}	
	function checkUser(){
		if($("#detailform").contents().find("#user-student-td").css("display") != "none"){
			if($("#detailform").contents().find("#user-student").val() == ""){
				$("#detailform").contents().find("#user-student-ex").html("不能为空");
				return false; 
			}else if($("#detailform").contents().find("#user-cellphone").val() == ""){
				$("#detailform").contents().find("#user-cellphone-ex").html("不能为空");
				return false; 
			}else if($("#detailform").contents().find("#user-usercode").val() == ""){
				$("#detailform").contents().find("#user-usercode-ex").html("不能为空");
				return false; 
			}else if($("#detailform").contents().find("#user-alias").val() == ""){
				$("#detailform").contents().find("#user-alias-ex").html("不能为空");
				return false;			
			}else{
				return true;
			}
		}else{
			if($("#detailform").contents().find("#user-cellphone").val() == ""){
				$("#detailform").contents().find("#user-cellphone-ex").html("不能为空");
				return false; 			
			}else if($("#detailform").contents().find("#user-usercode").val() == ""){
				$("#detailform").contents().find("#user-usercode-ex").html("不能为空");
				return false; 
			}else if($("#detailform").contents().find("#user-alias").val() == ""){
				$("#detailform").contents().find("#user-alias-ex").html("不能为空");
				return false; 
			}else{
				return true;
			}
		}
	}
	function checkUser1(){
		if($("#user-detailform").contents().find("#user-usercode").val() == ""){
			$("#user-detailform").contents().find("#user-usercode-ex").html("不能为空");
			return false; 
		}else if($("#user-detailform").contents().find("#user-alias").val() == ""){
			$("#user-detailform").contents().find("#user-alias-ex").html("不能为空");
			return false; 
		}else{
			return true;
		}	
	}
	
	function initSmPages(){
		var rcH = $(".body-right",parent.document).height() - $(".right-title").height()-3;
		$(".right-content").height(rcH);
		
		var cdsH = $(".right-content").height() - $(".content-title").height() - 40;
		$(".content-data-show").height(cdsH);
	}
})();